﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DATA.Base;
using DATA.BusinessObjects;
using DATA.ManagerObjects;
using NHibernate;

namespace BUS
{
    public class ChiTietDoanhThuTheoLoaiPhongBUS
    {
        #region Bình - thêm chi tiết doanh thu theo loại phòng
        public static Boolean ThemChiTietDoanhThuTheoLoaiPhong(Chitietdoanhthutheoloaiphong ctdttlp)
        {
            Boolean flag = false;
            ISession isession = NHibernateSessionManager.Instance.CreateISession();
            ITransaction iTrans = null;
            try
            {
                iTrans = isession.BeginTransaction();
                isession.Save(ctdttlp);
                iTrans.Commit();
                flag = true;
            }
            catch (Exception ex)
            {
                iTrans.Rollback();
                isession.Close();
                throw new Exception("Lỗi", ex);
            }
            return flag;
        }
        #endregion

        #region Bình - Lấy chi tiết doanh thu theo loại phòng mới nhất
        public static Chitietdoanhthutheoloaiphong LayChiTietDoanhThuTheoLoaiPhongMoiNhat()
        {
            Chitietdoanhthutheoloaiphong ctdttlp = null;

            IManagerFactory MF = new ManagerFactory();
            IChitietdoanhthutheoloaiphongManager CTDTTLPM = MF.GetChitietdoanhthutheoloaiphongManager();

            String hql = "FROM Chitietdoanhthutheoloaiphong ctdttlp "
                        + "WHERE length(ctdttlp.Id) = (Select MAX(length(ctdttlp.Id)) "
                                                + "from Chitietdoanhthutheoloaiphong ctdttlp) "
                        + "ORDER BY ctdttlp.Id desc";

            IList<Chitietdoanhthutheoloaiphong> list = CTDTTLPM.GetByQuery(hql);
            if(list.Count > 0)
                ctdttlp = list[0];
            return ctdttlp;
        }
        #endregion
    }
}
